import pandas as pd
import pymysql.cursors

data = pd.read_excel(r'../data/新-实时更新新型冠状病毒肺炎数据.xlsx')
var = data.values
# 创建对象
db = pymysql.connect(host='localhost', user= 'root', password='123123',
                     db='springdatajdbc', charset='utf8mb4')
cursor = db.cursor()
for i in var:
    # print(i)
    info_list = [i[0], i[1], i[2], i[3], i[4]]
    sql = 'insert into TestData values(%s,%s,%s,%s,%s)'
    cursor.execute(sql, info_list)
# # sql语句执性，单行插入
# info_list = ['刺杀,小说家', '雷佳音,杨幂', '2021-2-12']
# sql = 'insert into movieinfo values(%s,%s,%s)'
# # 列表传参
# cursor.execute(sql, info_list)
#
db.commit()
# # 关闭
cursor.close()
db.close()

print("成功。。。")
